/**
 * @file vdev.h
 * @brief vdev class
 * @author marco
 * @version v1.0
 * @date 2012-08-21
 */
#ifndef __VDEV_H_
#define __VDEV_H_

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

/** v4l2 header files */
#include <linux/videodev2.h>

/** QT header files */
#include <qobject.h>

#include "debug.h"
#include "common_macro.h"

#define BUFF_COUNTS 	4


struct buffer
{
    void * start;
    size_t length;
};
/**
 * @brief vdev
 *
 * This is open and control video device class
 */
class vdev : public QObject {
	Q_OBJECT
public:
    vdev();
    ~vdev();

	int get_system_video_dev_num();
	char* get_dev_path_by_id(const int id);

    int open_dev(const char* path);

	int get_capability();
	int get_fmtdesc();
	int get_cropcap();
	int set_format(const int w = -1, const int h = -1);
	int get_std();
	int init_mmap();
	void uninit_mmap();

	unsigned char* get_device_name();

    void close_dev();
private:
    int fd;
	struct v4l2_capability cap;
	struct v4l2_fmtdesc fmtdesc;
	struct v4l2_format format;
	struct v4l2_cropcap cropcap;
	struct v4l2_crop crop;
	struct v4l2_requestbuffers req;
	v4l2_std_id std;
    unsigned int n_buffers;
	buffer* buffers;
};

#endif
